package com.schoolvisitors.converter;

import com.schoolvisitors.enums.RoleEnum;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Converter(autoApply = true)
public class RoleEnumConverter implements AttributeConverter<RoleEnum, Integer> {

    @Override
    public Integer convertToDatabaseColumn(RoleEnum role) {
        return role.getCode();
    }

    @Override
    public RoleEnum convertToEntityAttribute(Integer roleCode) {
        return RoleEnum.fromCode(roleCode);
    }
}
